<html lang="zh">
<head>
    <link rel="icon" href="/static/images/title/air酱.ico" type="image/x-icon">
    <link rel="shortcut icon" href="/static/images/title/air酱.ico" type="image/x-icon">
    <meta charset="utf-8">
    <title>Air酱</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="/static/css/air-index.css" type="text/css" rel="stylesheet">
    <script src="/static/js/jquery-3.5.1.js"></script>
    <link href="/static/css/crawler.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="air-body">
    <div class="air-box">
        <div class="air-top-fix"></div>
        <div class="air-top">
            <a href="/" class="air-top-title">Air酱</a>
            <a href="/" class="air-top-a">首页</a>
            <a href="crawler" class="air-top-a">爬取机票</a>
            <a href="wechat" class="air-top-a">微信推送</a>
            <a id="login" href="login" class="air-top-a">登录</a>
        </div>
        <div class="air-top-fix"></div>
        <div class="air-center">

            <form action="sub_crawler_info" method="post" onsubmit="return change()">
                {% csrf_token %}
                <p>出发城市</p>
                <input name="start_city" type="text" id="air-input-start">
                <img src="/static/images/勾.svg" id="air-img-start" hidden="hidden" class="air-img-tip">
                <p>到达城市</p>
                <input name="end_city" type="text" id="air-input-end">
                <img src="/static/images/勾.svg" id="air-img-end" hidden="hidden" class="air-img-tip">
                <p>出行时间</p>
                <input type="date" name="start_time">
                <input type="submit" value="爬取" id="air-sub" >

            </form>
            <ul id="crawler-list">
                <li>
                    <span>出发地</span>
                    <span>到达地</span>
                    <span>出发时间</span>
                </li>
            </ul>
        </div>
        <div class="air-down">
        </div>
    </div>


</div>
{% csrf_token %}

</body>
<script>
    window.onload = function cookie_load() {
        var acookie = document.cookie.split(';')
        let valueOf = document.getElementsByName('csrfmiddlewaretoken')[0].value
        var flag = 0;
        let login_id = document.getElementById('login');
        for (var i = 0; i < acookie.length; i++) {
            var strings = acookie[i].split('=');
            if (strings[0] === ' login-cookie') {
                flag = 1;
                $.post('logging', {
                    strings,
                    csrfmiddlewaretoken: valueOf
                }, function (data) {
                    login_id.innerText = '退出';
                    login_id.href = 'exitLogin';
                })
            }
        }
        if (flag === 0) {
            login_id.innerText = '登录';
            login_id.href = 'login';
            window.location.href = 'login'
        }
        let crawler_list = window.document.getElementById('crawler-list');
        $.post('get_ex_info',{
            csrfmiddlewaretoken: valueOf
        },function (data) {
            for (let i = 0; i < data.ex_info.length; i++) {
                let startAirport = data.ex_info[i].start_airport;
                let endAirport = data.ex_info[i].end_airport;
                let startTime = data.ex_info[i].start_time;
                let element = document.createElement('li');
                let span1 = document.createElement('span');
                let span2 = document.createElement('span');
                let span3 = document.createElement('span');
                let a = document.createElement('a');
                span1.innerText = startAirport;
                span2.innerText=endAirport;
                span3.innerText=startTime;
                a.innerText='删除';
                a.href = 'del_ex?id='+data.ex_info[i].id
                element.append(span1);
                element.append(span2);
                element.append(span3);
                let span4 = document.createElement('span');
                span4.append(a)
                element.append(span4);
                crawler_list.append(element);
            }
        })

    }
</script>
<script src="/static/js/crawler.js" type="text/javascript"></script>

</html>